package org.apache.osgimaker.editors.conversions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;


public class CollectionFormatter<T> implements Converter<List<T>, Collection<? extends T>> {

    //private final Converter<String, ? super T> itemFormatter = new DefaultFormatter();

    public CollectionFormatter() {
        //this(new DefaultFormatter());
    }

/*    public CollectionFormatter(Converter<String, ? super T> itemFormatter) {
        this.itemFormatter = itemFormatter;
    }*/

    public List<T> convert(Collection<? extends T> input) throws IllegalArgumentException {
        List<T> result = new ArrayList<T>();
        if (input != null && !input.isEmpty()) {
            for(Iterator<? extends T> iter = input.iterator(); iter.hasNext(); ) {
                T item = iter.next();
                //buffer.append(itemFormatter.convert(item));
                //if(iter.hasNext())
                //    buffer.append(",\\\n\t");
                result.add(item);
            }
            //result = buffer.toString();
        }
        return result;
    }

}